package genomancer.ucsc.das2;

import genomancer.trellis.das2.model.Das2SegmentI;
import genomancer.trellis.das2.model.Das2SegmentsCapabilityI;
import genomancer.trellis.das2.model.Das2SegmentsResponseI;
import genomancer.trellis.das2.model.Das2SourceI;
import genomancer.trellis.das2.model.Das2SourcesResponseI;
import genomancer.trellis.das2.model.Das2TypeI;
import genomancer.trellis.das2.model.Das2TypesCapabilityI;
import genomancer.trellis.das2.model.Das2TypesResponseI;
import genomancer.trellis.das2.model.Das2VersionI;
import genomancer.ucsc.das2.modelimpl.UcscSourcesCapability;
import genomancer.util.MemCheck;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;


public class DbTest  {
    UcscSourcesCapability sources_cap;
    Das2SourcesResponseI sources_response;

    public static void main(String[] args)  {
	DbTest tester = new DbTest();
	tester.testDb();
    }

    public void testDb()  {
	MemCheck memer = new MemCheck();
	memer.start();
        try {
	    int source_count = 0;
	    int version_count = 0;
	    int type_count = 0;
	    int segment_count = 0;

            sources_cap = new UcscSourcesCapability(new URI("test:ucsc/das2/"), "sources");
            sources_response = sources_cap.getSources();
            List<Das2SourceI> sources = sources_response.getSources();
	    source_count = sources.size();
            System.out.println("sources count: " + source_count);
	    for (Das2SourceI source : sources)  {
		List<Das2VersionI> versions = source.getVersions();
		version_count += versions.size();
	    }
	    System.out.println("version count: " + version_count);

	    int current_version = 0;
	    for (Das2SourceI source : sources)  {
		for (Das2VersionI version : source.getVersions())  {
		    try  {
			current_version++;
			System.out.println("getting types for version: " + current_version + ", " + 
					   version.getLocalURIString());
			Das2TypesCapabilityI types_cap = 
			    (Das2TypesCapabilityI)version.getCapability("types");
			Das2TypesResponseI types_response = types_cap.getTypes();
			List<Das2TypeI> types = types_response.getTypes();
			type_count += types.size();

			/*
			Das2SegmentsCapabilityI segments_cap = 
			    (Das2SegmentsCapabilityI)version.getCapability("segments");
			Das2SegmentsResponseI segments_response = segments_cap.getSegments();
			List<Das2SegmentI> segments = segments_response.getSegments();
			segment_count += segments.size();
			*/

			System.out.println("     types: " + types.size() + ",  total: " + type_count);
			// System.out.println("     segments: " + segments.size() + ", total: " + segment_count);
			// memer.report();
		    }
		    catch (Exception ex)  {
			ex.printStackTrace();
		    }
		}
	    }
	    memer.report();
	    System.out.println();
	    System.out.println("type count: " + type_count);

        } catch (URISyntaxException ex) {
            Logger.getLogger(DbTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

} 